/*
 * Copyright (c) 2020 MediaTek Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#pragma once

enum pmic_psc_reg_name {
    RG_PWRKEY_KEY_MODE,
    RG_PWRKEY_RST_EN,
    RG_PWRHOLD,
    RG_CRST,
    JUST_SMART_RST,
    JUST_PWRKEY_RST,
    RG_CLR_JUST_SMART_RST,
    CLR_JUST_RST,
    RG_SMART_RST_SDN_EN,
    RG_SMART_RST_MODE,
    RG_CPS_W_KEY,
    SWCID,
    RG_RSV_SWREG,
};

struct pmic_psc_reg {
    u16 reg_addr;
    u16 reg_mask;
    u16 reg_shift;
};

struct pmic_psc_config {
    int (*read_field)(u16 reg, u16 *val, u16 mask, u16 shift);
    int (*write_field)(u16 reg, u16 val, u16 mask, u16 shift);
    const struct pmic_psc_reg *regs;
};

#define PMIC_PSC_REG(_reg_name, addr, shift) \
    [_reg_name] = {         \
        .reg_addr = addr,   \
        .reg_mask = 0x1,    \
        .reg_shift = shift, \
    }

int is_pmic_long_press_reset(void);
int clr_pmic_long_press_reset(void);
int is_pmic_smart_reset(void);
int clr_pmic_smart_reset(void);
int enable_pmic_smart_reset(bool enable);
int enable_pmic_smart_reset_shutdown(bool enable);
int pmic_get_chip_version(void);
u8 pmic_get_swreg(void);
int pmic_set_swreg(u8 val);
int pmic_psc_register(const struct pmic_psc_config *psc);
